package action;

import character.Character;
import board.BoardUtil;
import game.DataStore;
import misc.Vector3i;

public class MoveAction extends Action {
    public static final int DEFAULT_TOTAL_TICKS_CARDINAL = 5;
    public static final int DEFAULT_TOTAL_TICKS_DIAGONAL = 7;
    private Vector3i destination;
    
    @Deprecated
    public MoveAction() {}
    
    public MoveAction(Character character, Vector3i destination) {
        super(character, DEFAULT_TOTAL_TICKS_CARDINAL);
	if(character.getActionQueue().getQueuedLocation().distance(destination) == BoardUtil.DISTANCE_DIAGONAL_1) {
	    totalTicks = MoveAction.DEFAULT_TOTAL_TICKS_DIAGONAL;
	    this.ticksRemaining = totalTicks;
	}
        this.destination = destination;
    }

    @Override
    protected void start() {}
    
    @Override
    protected void complete() {
        charControl.stopWalking();
	character.movementComplete(destination);
	System.out.println(character.getBoardLocation());
    }
    
    @Override
    protected void tick() {
        float distanceLeft = charControl.getPhysicsLocation().distance(BoardUtil.boardToWorld(destination));
        float speedReq = (distanceLeft/ticksRemaining)/DataStore.TIME_PER_TICK;
        charControl.setWalk(destination, speedReq/35); //value estimated based on what looks good
    }
    
    @Override
    public void pause() {
        charControl.stopWalking();
    }
    
    @Override
    public void unpause() {}
    
    public Vector3i getDestination() {
	return destination;
    }
    public void setDestination(Vector3i destination) {
	this.destination = destination;
    }
}
